package com.antis.olsl.data.purchase;

import androidx.recyclerview.widget.LinearLayoutManager;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.antis.olsl.arouterlib.DataRoutePath;
import com.antis.olsl.base.BaseActivity;
import com.antis.olsl.data.adapter.PurchaseGoodsFiledListAdapter;
import com.antis.olsl.data.databinding.ActivityPurchaseSlipGoodsDetailsBinding;
import com.antis.olsl.library.bean.GoodsFiledInfo;
import com.antis.olsl.library.bean.GoodsInfo;
import com.antis.olsl.library.utils.StringUtils;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;

/**
 * @ProjectName: ATS_OLSL
 * @Package: com.antis.olsl.activity.purchaseQuery
 * @ClassName: PurchaseSlipGoodsDetailsActivity
 * @Description: 采购单商品详情
 * @Author: 羊琪
 * @CreateDate: 2020/3/30 19:48
 * @UpdateDate: 2020/3/30 19:48
 * @UpdateRemark: 更新说明
 * @Version: 1.0
 */
@Route(path = DataRoutePath.ACTIVITY_PURCHASE_SLIP_GOODS_DETAIL)
public class PurchaseSlipGoodsDetailsActivity extends BaseActivity<ActivityPurchaseSlipGoodsDetailsBinding> {

    private ArrayList<GoodsFiledInfo> filedInfos = new ArrayList<>();
    private PurchaseGoodsFiledListAdapter adapter;
    private boolean fromSalesroom = false;
    private String productId;
    private String purchaseNumber;

    @Override
    protected ActivityPurchaseSlipGoodsDetailsBinding getViewBinding() {
        return ActivityPurchaseSlipGoodsDetailsBinding.inflate(getLayoutInflater(), baseBinding.getRoot(), true);
    }

    @Override
    protected void initViews() {
        viewBinding.recyclerView.setLayoutManager(new LinearLayoutManager(this));
        adapter = new PurchaseGoodsFiledListAdapter(filedInfos);
        viewBinding.recyclerView.setAdapter(adapter);
    }

    @Override
    protected void initData() throws IllegalAccessException {
        getDetails();
    }

    /**
     * 获取商品详情
     */
    private void getDetails() {
        HashMap<String, Object> map = new HashMap<>();
        map.put("purchaseNumber", purchaseNumber);
        map.put("productId", productId);
        // okHttpClient.postJsonObjectParams(fromSalesroom ? UrlServerConnections.GET_PURCHASE_GOODS_DETAILS : UrlServerConnections.GET_PURCHASE_GOODS_DETAILS, map, GetPurchaseGoodsDetailsRes.class);
    }

//    @Override
//    public void successResponse(BaseRes baseRes) {
//        if (baseRes instanceof GetPurchaseGoodsDetailsRes) {
//            GetPurchaseGoodsDetailsRes goodsDetailsRes = (GetPurchaseGoodsDetailsRes) baseRes;
//            setData(goodsDetailsRes.getContent());
//        }
//    }

    private void setData(GoodsInfo goodsInfo) {
        if (goodsInfo == null) {
            return;
        }
        filedInfos.add(new GoodsFiledInfo("商品名称", goodsInfo.getProductName()));
        filedInfos.add(new GoodsFiledInfo("商品编码", goodsInfo.getProductCode()));
        filedInfos.add(new GoodsFiledInfo("商品条码", goodsInfo.getBarCode()));
        filedInfos.add(new GoodsFiledInfo("供应商名称", goodsInfo.getSupplierName()));
        filedInfos.add(new GoodsFiledInfo("品牌名称", goodsInfo.getBrandName()));
        filedInfos.add(new GoodsFiledInfo("商品规格", goodsInfo.getSpecification()));
        filedInfos.add(new GoodsFiledInfo("商品单位", goodsInfo.getUnit()));
        filedInfos.add(new GoodsFiledInfo("装箱规格", goodsInfo.getPackingSpecification()));
        filedInfos.add(new GoodsFiledInfo("零售价", StringUtils.getCommaFormat(new BigDecimal(goodsInfo.getRetailPrice())) + "元"));
        filedInfos.add(new GoodsFiledInfo("验收仓库", goodsInfo.getWarehouseName()));
        filedInfos.add(new GoodsFiledInfo("采购数量", StringUtils.getCommaFormat(new BigDecimal(goodsInfo.getPurchaseNum()))));
        filedInfos.add(new GoodsFiledInfo("采购成本", StringUtils.getCommaFormat(new BigDecimal(goodsInfo.getPurchasePrice())) + "元"));
        filedInfos.add(new GoodsFiledInfo("含税采购成本", StringUtils.getCommaFormat(new BigDecimal(goodsInfo.getPriceTax())) + "元"));
        filedInfos.add(new GoodsFiledInfo("零售价金额", StringUtils.getCommaFormat(new BigDecimal(goodsInfo.getTotalPrice())) + "元"));
        adapter.setList(filedInfos);
    }
}
